package game.util;

import game.ChancePair;
import game.Constants;

import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Vector;

public class InterestUtil {

	public abstract class Interest {
		private String type;

		public Interest() {
			this.type = Util.GetRandomListValue(getTypes());
		}

		public String getName() {
			return type;
		}

		/**
		 * Verbs used in accordance with the interest
		 * 
		 * @return
		 */
		public abstract List<String> getVerbs();

		/**
		 * Subtypes of the interest
		 * 
		 * @return
		 */
		public abstract List<String> getTypes();

		/**
		 * Conversation's about the topic of interest
		 * 
		 * @return
		 */
		public abstract List<String> getCommunications();

		@Override
		public String toString() {
			return this.type;
		}

		@Override
		public boolean equals(Object obj) {
			if (obj instanceof Interest)
				return this.type.equals(((Interest) obj).type);
			return false;
		}

	}

	public class MusicInterest extends Interest {

		@Override
		public List<String> getVerbs() {
			return Arrays.asList(Constants.MUSIC_VERBS);
		}

		@Override
		public List<String> getTypes() {
			return Arrays.asList(Constants.MUSIC_TYPES);
		}

		@Override
		public List<String> getCommunications() {
			// TODO Auto-generated method stub
			return new Vector<String>();
		}
	}

	public class SportInterest extends Interest {

		@Override
		public List<String> getVerbs() {
			return Arrays.asList(Constants.SPORT_VERBS);
		}

		@Override
		public List<String> getTypes() {
			return Arrays.asList(Constants.SPORT_TYPES);
		}

		@Override
		public List<String> getCommunications() {
			// TODO Auto-generated method stub
			return new Vector<String>();
		}
	}

	public class InstrumentInterest extends Interest {

		@Override
		public List<String> getVerbs() {
			return Arrays.asList(Constants.INSTRUMENT_VERBS);
		}

		@Override
		public List<String> getTypes() {
			return Arrays.asList(Constants.INSTRUMENT_TYPES);
		}

		@Override
		public List<String> getCommunications() {
			// TODO Auto-generated method stub
			return new Vector<String>();
		}
	}

	public class HobbyInterest extends Interest {

		@Override
		public List<String> getVerbs() {
			return Arrays.asList(Constants.HOBBY_VERBS);
		}

		@Override
		public List<String> getTypes() {
			return Arrays.asList(Constants.HOBBY_TYPES);
		}

		@Override
		public List<String> getCommunications() {
			// TODO Auto-generated method stub
			return new Vector<String>();
		}
	}

	public class GeneralInterest extends Interest {

		@Override
		public List<String> getVerbs() {
			return Arrays.asList(Constants.GENERAL_VERBS);
		}

		@Override
		public List<String> getTypes() {
			return Arrays.asList(Constants.GENERAL_TYPES);
		}

		@Override
		public List<String> getCommunications() {
			// TODO Auto-generated method stub
			return new Vector<String>();
		}
	}

	public Collection<Interest> getRandomInterests() {
		final Collection<Interest> interests = new Vector<Interest>();

		int interestsToAdd = Util.GetRandomIntBetween(
				Constants.INTEREST_MIN_NUM, Constants.INTEREST_MAX_NUM);

		while (interestsToAdd != 0) {
			Collection<ChancePair<Interest>> test = new Vector<ChancePair<Interest>>();
			// Get music interest
			test.add(new ChancePair<Interest>(new MusicInterest(),
					Constants.INTEREST_MUSIC_CHANCE));
			// Get sport interest
			test.add(new ChancePair<Interest>(new SportInterest(),
					Constants.INTEREST_SPORT_CHANCE));
			// Get instrument interest
			test.add(new ChancePair<Interest>(new InstrumentInterest(),
					Constants.INTEREST_INSTRUMENT_CHANCE));
			// Get hobby interest
			test.add(new ChancePair<Interest>(new HobbyInterest(),
					Constants.INTEREST_HOBBY_CHANCE));
			// Get other interest
			test.add(new ChancePair<Interest>(new GeneralInterest(),
					Constants.INTEREST_OTHER_CHANCE));

			final Interest randomInterst = Util.GetRandomFromChancePair(test);
			if (randomInterst != null && !interests.contains(randomInterst)) {
				interests.add(randomInterst);
				interestsToAdd--;
			}
		}

		return interests;
	}
}
